//
//  DSSHPointDetailVC.m
//  DSSH
//
//  Created by lcy on 16/4/6.
//  Copyright © 2016年 lcy. All rights reserved.
//

#import "DSSHPointDetailVC.h"
#import "UIView+Round.h"
#import "MeCommentCell.h"
#import "DSSHMeRepairsDeatailCell.h"
#import "ProjectPointDetailCell.h"
#import "ProjectBtn.h"
#import "CusNavButton.h"
@interface DSSHPointDetailVC ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView*detailTableView;
@property(nonatomic,strong)UIView*bottomView;
@end

@implementation DSSHPointDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViewAndData];
    [self setupConstraints];
    // Do any additional setup after loading the view.
}
-(void)setupViewAndData
{
    self.title = @"点位详情";
    self.extendedLayoutIncludesOpaqueBars = NO;
    self.edgesForExtendedLayout = UIRectEdgeBottom | UIRectEdgeLeft | UIRectEdgeRight;
    UIBarButtonItem * backBarBtn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fanhui"] style:UIBarButtonItemStylePlain target:self action:@selector(backBarBtnClick)];
    self.navigationItem.leftBarButtonItem = backBarBtn;

    UIButton * qipaoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [qipaoBtn setBackgroundImage:[UIImage imageNamed:@"qipao"] forState:UIControlStateNormal];
    qipaoBtn.frame = CGRectMake(0, 0, 50, 25);
    [qipaoBtn setTitle:@"4580评论" forState:UIControlStateNormal];
    [qipaoBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    qipaoBtn.titleLabel.font = FONT(9);
    //添加右侧的按钮
    UIBarButtonItem * rightBtn1 = [[UIBarButtonItem alloc]initWithCustomView:qipaoBtn];
   
    UIBarButtonItem * rightBtn2 = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fengxiang"] style:UIBarButtonItemStylePlain target:self action:nil];
    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:rightBtn2,rightBtn1,nil];
    self.detailTableView = [[UITableView alloc]init];
    self.detailTableView.delegate = self;
    self.detailTableView.dataSource = self;
    self.detailTableView.layer.borderWidth = 1;
    self.detailTableView.layer.borderColor = [[UIColor groupTableViewBackgroundColor]CGColor];
    [self.detailTableView getRoundView:5];
    [self.view addSubview:self.detailTableView];
    
    self.bottomView = [UIView new];
    self.bottomView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:self.bottomView];
    
    UIButton * writeBtn = [UIButton new];
    writeBtn.frame = CGRectMake(80*WIDTH_SCALE, 5*HIGHT_SCALE, 35*WIDTH_SCALE, 50*HIGHT_SCALE);
    UIImageView * bgImageView = [[UIImageView alloc]init];
    [writeBtn addSubview:bgImageView];
    UILabel * bottomLabel = [UILabel new];
    [writeBtn addSubview:bottomLabel];
    bgImageView.frame = CGRectMake(5*WIDTH_SCALE, 0, 25*WIDTH_SCALE, 24*HIGHT_SCALE);
    bottomLabel.frame = CGRectMake(0, 24*HIGHT_SCALE, 35*WIDTH_SCALE, 24*HIGHT_SCALE);
    bottomLabel.textAlignment = NSTextAlignmentCenter;
    bottomLabel.text = @"写评论";
    bottomLabel.font = FONT(8);
    bottomLabel.textColor = [UIColor grayColor];
    bgImageView.image = [UIImage imageNamed:@"xie"];
    [self.bottomView addSubview:writeBtn];
    
    UIButton * repairBtn = [UIButton new];
    repairBtn.frame = CGRectMake(ZYAppWidth-(80+35)*WIDTH_SCALE, 5*HIGHT_SCALE, 35*WIDTH_SCALE, 50*HIGHT_SCALE);
    UIImageView * bgImageView1 = [[UIImageView alloc]init];
    [repairBtn addSubview:bgImageView1];
    UILabel * bottomLabel1 = [UILabel new];
    [repairBtn addSubview:bottomLabel1];
    bgImageView1.frame = CGRectMake(5*WIDTH_SCALE, 0, 25*WIDTH_SCALE, 24*HIGHT_SCALE);
    bottomLabel1.frame = CGRectMake(0, 24*HIGHT_SCALE, 35*WIDTH_SCALE, 24*HIGHT_SCALE);
    bottomLabel1.textAlignment = NSTextAlignmentCenter;
    bottomLabel1.text = @"我要报修";
    bottomLabel1.font = FONT(8);
    bottomLabel1.textColor = [UIColor grayColor];
    bgImageView1.image = [UIImage imageNamed:@"sheshibaoxiu"];
    [self.bottomView addSubview:repairBtn];

}
-(void)setupConstraints
{
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).with.offset(0);
        make.right.equalTo(self.view).with.offset(0);
        make.bottom.equalTo(self.view.mas_bottom).with.offset(0);
        make.height.mas_equalTo(50*HIGHT_SCALE);
    }];

    [self.detailTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).with.offset(5*WIDTH_SCALE);
        make.right.equalTo(self.view).with.offset(-5*WIDTH_SCALE);
        make.top.equalTo(self.view.mas_top).with.offset(5*HIGHT_SCALE);
        make.bottom.equalTo(self.bottomView.mas_top).with.offset(-10*HIGHT_SCALE);
    }];
    
}
-(void)backBarBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 4;
    }
    if (section == 1)
    {
        return 2;
    }
    else
    {
        return 1;
    }
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        NSMutableArray * array1 = [[NSMutableArray alloc]initWithObjects:@"项目名称：",@"项目地址：",@"项目编号：",@"点位路径：", nil];
        NSMutableArray * titleArray = [[NSMutableArray alloc]initWithObjects:@"上画",@"未来之光",@"201603041454",@"未来之光1栋1单元1梯", nil];
        NSMutableArray * imageArray1 = [[NSMutableArray alloc]initWithObjects:@"iconfontrenwu",@"iconfont_dizhi",@"gerenxinxi-0",@"ditu1", nil];
        DSSHMeRepairsDeatailCell * cell = [tableView cellForRowAtIndexPath:indexPath];
        if (!cell)
        {
            cell = [[NSBundle mainBundle]loadNibNamed:@"DSSHMeRepairsDeatailCell" owner:nil options:nil][0];
        }
        cell.headImage.image = [UIImage imageNamed:imageArray1[indexPath.row]];
        cell.titleLabel.text = array1[indexPath.row];
        cell.nameLabel.text = titleArray[indexPath.row];
        return cell;
    }
    if (indexPath.section == 1)
    {
        if (indexPath.row == 0)
        {
            ProjectPointDetailCell * cell = [tableView cellForRowAtIndexPath:indexPath];
            if (!cell)
            {
                cell = [[NSBundle mainBundle]loadNibNamed:@"ProjectPointDetailCell" owner:nil options:nil][0];
            }
            [cell.guanggaoImageView getRoundView:5];
            [cell.redLabel getRoundView:5];
            cell.redLabel.layer.borderWidth = 1;
            cell.redLabel.layer.borderColor = [[UIColor redColor]CGColor];
            return cell;
        }else
        {
            UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellID2"];
            if (!cell)
            {
                cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellID2"];
            }
            NSArray * imageArray = [[NSArray alloc]initWithObjects:@"liulanqi3",@"iconfont_dianzan-0",@"dianzan", nil];
            NSArray * dataArray = [[NSArray alloc]initWithObjects:@" 1800",@" 9",@" 98", nil];
            for (int i = 0; i<3; i++)
            {
                UIButton *button = [[UIButton alloc] init];
                button.tag = i+1;
                float btnWidth = (ZYAppWidth-120*WIDTH_SCALE)/3;
                button.frame = CGRectMake(30*WIDTH_SCALE+(30*WIDTH_SCALE+btnWidth)*i, 7, btnWidth, 30);
                [button setTitle:dataArray[i] forState:UIControlStateNormal];
                [button setImage:[UIImage imageNamed:imageArray[i]] forState:UIControlStateNormal];
                [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
                button.titleLabel.textAlignment = NSTextAlignmentCenter;
                button.titleLabel.font = [UIFont systemFontOfSize:13];
                [cell.contentView addSubview:button];

            }
            return cell;
        }
    }
    if (indexPath.section == 2)
    {
        MeCommentCell * cell = [tableView cellForRowAtIndexPath:indexPath];
        if (!cell)
        {
            cell = [[NSBundle mainBundle]loadNibNamed:@"MeCommentCell" owner:nil options:nil][0];
        }
        return cell;

    }else
    {
        return nil;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        return 44;
    }
    if (indexPath.section == 1)
    {
        if (indexPath.row == 0)
        {
            return 200;
        }else
        {
            return 44;
        }
    }else
    {
        return 160;
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
